<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Java2019-C190708</title>

        <!-- Tell the browser to be responsive to screen width -->
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

        <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/ionicons/css/ionicons.min.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
    </head>

    <body class="hold-transition login-page">
        <div class="login-box">
            <div class="login-logo">
                <a href="#"><b>C190708</b>管理系统</a>
            </div>
            <!-- /.login-logo -->
            <div class="login-box-body">
                <p class="login-box-msg">登录系统</p>
                <h5 style="color: red" id="sp"></h5>
<%--                <form action="${pageContext.request.contextPath}/login" method="post" id="form">--%>
                    <div class="form-group has-feedback">
                        <input type="text" name="loginName" class="form-control" placeholder="用户名">
                        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                    </div>
                    <div class="form-group has-feedback">
                        <input type="password" name="loginPwd" class="form-control" placeholder="密码">
                        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
                    </div>
                    <div class="row">
                        <div class="col-xs-8">
                            <div class="checkbox icheck">
                                <label><input type="checkbox"> 记住 下次自动登录</label>
                            </div>
                        </div>
                        <!-- /.col -->
                        <div class="col-xs-4">
                            <button class="btn btn-primary btn-block btn-flat" id="login">登录</button>
                        </div>
                        <!-- /.col -->
                    </div>
<%--                </form>--%>

                <a href="#">忘记密码</a><br>


            </div>
            <!-- /.login-box-body -->
        </div>
        <!-- /.login-box -->

        <!-- jQuery 2.2.3 -->
        <!-- Bootstrap 3.3.6 -->
        <!-- iCheck -->
        <script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
        <script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
        <script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
        <script>
            $(function () {
                $('input').iCheck({
                    checkboxClass: 'icheckbox_square-blue',
                    radioClass: 'iradio_square-blue',
                    increaseArea: '20%' // optional
                });

                $("#login").click(function () {
                    if($("input[name=loginName]").val()==''){
                        $("#sp").text("请输入用户名！");
                    }
                    else if($("input[name=loginName]").val()==null){
                        $("#sp").text("请输入用户名！");
                    }
                    else if($("input[name=loginPwd]").val()==''){
                        $("#sp").text("请输入密码！");
                    }
                    else if($("input[name=loginPwd]").val()==null){
                        $("#sp").text("请输入密码！");
                    }
                    else {
                        var url="http://localhost:8080/erp/login";
                        var data={"loginName":$("input[name=loginName]").val(),"loginPwd":$("input[name=loginPwd]").val()};
                        ajax(url,data)
                    }
                })
            });

            function ajax(url,data) {
                $.ajax({
                    url:url,
                    type:"Post",
                    data:data,
                    dataType:"text",
                    success:function (res) {
                        if (res==="false"){
                            $("#sp").text("用户名或密码错误！");
                        }
                        else{
                            window.location.href="http://localhost:8080/erp/app"
                        }
                    }
                })
            }
        </script>
    </body>

</html>